import Vue from 'vue'
import VueRouter from 'vue-router'

import homeRouter from '../router/home'
import classifyRouter from '../router/classify'
import cartRouter from '../router/cart'
import mineRouter from '../router/mine'
import Tijiaodingdan from '../router/Tijiaodingdan'
import detailRouter from '../router/detail'
import NotFound from '../views/404ye'
import listRouter from "../router/list"

import loginRouter from '../router/login'
import registerRouter from '../router/register/index'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    // *  404页面指定
    path: '*',
    component: NotFound
  },
  homeRouter,
  classifyRouter,
  cartRouter,
  mineRouter,
  Tijiaodingdan,
  detailRouter,
  listRouter,
  loginRouter,
  registerRouter
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

router.beforeEach((to,from,next)=>{
  var token = localStorage.getItem('isLogin')
  if(to.meta.isLogin === true && !token){
    next('/login')
  }
  next()
})

export default router
